package com.yjc.sunnyweather.logic.dao

import com.google.gson.Gson
import com.yjc.sunnyweather.logic.model.Place
import com.yjc.sunnyweather.util.DataStoreUtil

object PlaceDao {

    private const val PLACE_KEY = "place"

    fun savePlace(place: Place) = DataStoreUtil.putString(PLACE_KEY,Gson().toJson(place))

    fun getSavedPlace(): Place? {
        val value = DataStoreUtil.getString(PLACE_KEY, "")
        if (value.isEmpty()){
            return null;
        }
        return  Gson().fromJson(value, Place::class.java)
    }



}